package _11_整理题目._0_工具集;


import org.junit.Test;

import java.util.TreeSet;

public class _05_排序_以类为单位 {

    class Pair {
        int i;
        String str;

        public Pair(int i, String str) {
            this.i = i;
            this.str = str;
        }
    }

    public String testCompare(String[] strings){
        int n = strings.length;
        TreeSet<Pair> treeSet = new TreeSet<>((p1, p2) -> {
            if (!p1.str.equals(p2.str)) {
                return p1.str.compareTo(p2.str);
            } else {
                return p1.i - p2.i;
            }
        });
        for (int i = 0; i < n; i++) {
            Pair pair = new Pair(i, strings[i]);
            treeSet.add(pair);
        }
        return treeSet.first().str;
    }

    @Test
    public void main(){
        String[] strings = {"07204","2984","07204","2911","7393","3304661051423"};
        System.out.println(testCompare(strings));
    }

}
